package com.itdaan.portal.business.controller;
import org.apache.commons.lang.StringUtils;

import com.itdaan.portal.business.domain.BaseDomain;


/**
 * @Description: 基础控制类
 * @Author www.itdaan.com
 * 
 */
public class BaseController {
	public static final String ENCODE_UTF8 = "UTF-8";
	public static final String ENCODE_GBK = "GBK";
	public static final String OK = "OK";
	public static final boolean SUCCESS = true;
	public static final boolean ERROR = false;
	public static final boolean YES = true;
	
    public void setPagination(BaseDomain domain, Integer start, Integer rp) {
        domain.setPage(start == 0 ? 1 : Double.valueOf(Math.ceil(start / rp)).intValue());
        domain.setStart(start);
        domain.setLimit(rp);
        domain.setEnd(start+rp);
    }

    /**
     * 设置字段排序列
     * @param domain
     * @param dbColumn 数据表字段名称
     * @param sortName ASC / DESC
     */
    public void setSort(BaseDomain domain, String dbColumn, String sortName) {
        if (StringUtils.isEmpty(sortName)) return;
        sortName = (sortName == null || sortName.length()<=0) ? "ASC" : sortName;
        domain.setSortName(dbColumn);
        domain.setSortOrder(sortName);
    }
    
    /**
     * 设置字段排序列
     * @param domain
     * @param dbColumn 数据表字段名称
     * @param sortName ASC / DESC
     */
    public void setSort(BaseDomain domain,  String sortName) {
        if (StringUtils.isEmpty(sortName)) return;
        String[] arr=sortName.split(" ");
        domain.setSortName(arr[0]);
        domain.setSortOrder(arr[1]);
    }
    
}
